package org.xyl.context;

import java.util.*;

/**
 * 运行时上下文 - 存储设备、网络、平台的实时状态数据
 */
public class RuntimeContext {
    private String deviceId;
    private Map<String, Object> deviceStatus;
    private List<LogEntry> recentLogs;
    private long lastUpdateTime;
    
    public RuntimeContext(String deviceId) {
        this.deviceId = deviceId;
        this.deviceStatus = new HashMap<>();
        this.recentLogs = new ArrayList<>();
        this.lastUpdateTime = System.currentTimeMillis();
    }
    
    public void addStatusMetric(String name, Object value) {
        this.deviceStatus.put(name, value);
    }
    
    public void addLogEntry(LogEntry logEntry) {
        this.recentLogs.add(logEntry);
    }
    
    public String getDeviceId() {
        return deviceId;
    }
    
    public Map<String, Object> getDeviceStatus() {
        return deviceStatus;
    }
    
    public List<LogEntry> getRecentLogs() {
        return recentLogs;
    }
    
    public long getLastUpdateTime() {
        return lastUpdateTime;
    }
    
    /**
     * 日志条目类
     */
    public static class LogEntry {
        private String level;
        private String message;
        private Date timestamp;
        
        public LogEntry(String level, String message, Date timestamp) {
            this.level = level;
            this.message = message;
            this.timestamp = timestamp;
        }
        
        public String getLevel() {
            return level;
        }
        
        public String getMessage() {
            return message;
        }
        
        public Date getTimestamp() {
            return timestamp;
        }
    }
}